package com.pubsys.main.server.rpc.buscareferencia;

import java.sql.SQLException;
import java.util.ArrayList;

import com.pubsys.main.client.rpc.buscareferencias.BuscaReferenciasRPC;
import com.pubsys.main.server.database.Database;
import com.pubsys.main.server.database.fetchers.ReferenciaFetcher;
import com.pubsys.main.server.rpc.SisWebRemoteServiceServlet;
import com.pubsys.main.shared.exceptions.RPCExceptions;
import com.pubsys.main.shared.model.FiltroReferencia;
import com.pubsys.main.shared.model.Referencia;

public class BuscaReferenciasRPCImpl extends SisWebRemoteServiceServlet implements BuscaReferenciasRPC {
	private static final long serialVersionUID = 1936047818403567637L;


	public ArrayList<Referencia> buscaReferenciaUsandoFiltro(FiltroReferencia filtro) throws RPCExceptions {
		
		String where = "where 'titulo' like '%"  + filtro.getTitulo() + "%' OR " +
					   		" 'local' like '%" + filtro.getLocal() + "%'";

		ReferenciaFetcher fetcher = new ReferenciaFetcher(where);
		
		
		try {
			Database.getDatabaseInstance().doSelect(fetcher);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RPCExceptions("Ooooops erro no banco..");
		}
		
		
		
		return fetcher.getFetchedData();
	}
}
